package cn.fl.risk.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.risk.condition.RskAppoRecQueryCondition;
import cn.fl.risk.dto.RskAppoRecDTO;
import cn.fl.risk.service.IRskAppoRecApiService;
import cn.fl.risk.service.IRskAppoRecService;
import cn.fl.risk.transform.RskAppoRecVOTransform;
import cn.fl.risk.vo.RskAppoRecVO;

/**
 * @Description: 催收预约表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class RskAppoRecServiceImpl implements IRskAppoRecService {

	/**
     * 日志
     */
    @SuppressWarnings("unused")
    private static final Logger logger = LoggerFactory.getLogger(RskAppoRecServiceImpl.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IRskAppoRecApiService rskAppoRecApiService;
	/**
     * 数据字典服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

	@Override
	public RskAppoRecVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)) return null;
		RskAppoRecDTO dto = this.rskAppoRecApiService.selectRskAppoRecById(id);
		return RskAppoRecVOTransform.toVO(dto);
	}

	@Override
	public Long add(RskAppoRecVO entity) throws BaseException{
		if(null == entity) return null;
		return this.rskAppoRecApiService.addRskAppoRec(RskAppoRecVOTransform.toDTO(entity));
	}

	/**
	 * 新增
	 * @param list
	 * @return
	 */
	public boolean add(List<RskAppoRecVO> list) throws BaseException{
		if(CollectionUtils.isEmpty(list)){
			return false;
		}
		return this.rskAppoRecApiService.addRskAppoRec(RskAppoRecVOTransform.toDTOList(list));
	}

	@Override
	public boolean removeByIds(List<Long> ids) throws BaseException{
		if(CollectionUtils.isEmpty(ids)) return false;
		return this.rskAppoRecApiService.removeRskAppoRecByIds(ids,CurrentThreadContext.getCurrentUserId());
	}

	@Override
	public boolean modify(RskAppoRecVO entity) throws BaseException{
		if(null == entity) return false;
		return this.rskAppoRecApiService.modifyRskAppoRec(RskAppoRecVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
        RskAppoRecQueryCondition condition=null;
        if(null == page) {
            page = new Pager();
            page.setCondition(new RskAppoRecQueryCondition());
        }
		condition=(RskAppoRecQueryCondition)page.getCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		page=this.rskAppoRecApiService.searchRskAppoRecListPage(page);
		if(CollectionUtils.isNotEmpty(page.getResultList())){
            List<RskAppoRecVO> voList=RskAppoRecVOTransform.toVOList((List<RskAppoRecDTO>)page.getResultList());
            //this.setDictData(voList);
            page.setResultList(voList);
        }
        return page;
	}
	
	@Override
	public List<RskAppoRecVO> searchList(RskAppoRecQueryCondition condition) throws BaseException{
		if(null == condition) condition=new RskAppoRecQueryCondition();
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
		condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		List<RskAppoRecVO> voList=RskAppoRecVOTransform.toVOList(this.rskAppoRecApiService.searchRskAppoRecList(condition));
		this.setDictData(voList);
		return voList;
	}
	
    /**
     * 添加数据字典名称
     * @param voList
     */
	public void setDictData(List<RskAppoRecVO> voList){
		if(CollectionUtils.isEmpty(voList)) return;
		/*Map<String, String> _CdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, RskAppoRecConstant.CODE_CD);
		for(RskAppoRecVO vo:voList){
			if (_CdMap != null && _CdMap.containsKey(vo.getCd())) {
            	vo.setCdNm(_CdMap.get(vo.getCd()));
        	}	
		}*/
	}
	    
}
